/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.user.platform.controller;

import com.yami.shop.user.comment.model.UserGrowthLog;
import com.yami.shop.user.comment.service.UserGrowthLogService;
import com.yami.shop.common.annotation.SysLog;

import javax.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 * 用户成长值记录
 *
 * @author LGH
 * @date 2020-02-26 16:03:14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user/userGrowthLog" )
public class UserGrowthLogController {

    private final UserGrowthLogService userGrowthLogService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userGrowthLog 用户成长值记录
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<UserGrowthLog>> getUserGrowthLogPage(PageParam<UserGrowthLog> page, UserGrowthLog userGrowthLog) {
        return ResponseEntity.ok(userGrowthLogService.getPage(page,userGrowthLog));
    }


    /**
     * 通过id查询用户成长值记录
     * @param logId id
     * @return 单个数据
     */
    @GetMapping("/info/{logId}" )
    public ResponseEntity<UserGrowthLog> getById(@PathVariable("logId") Long logId) {
        return ResponseEntity.ok(userGrowthLogService.getById(logId));
    }

    /**
     * 新增用户成长值记录
     * @param userGrowthLog 用户成长值记录
     * @return 是否新增成功
     */
    @SysLog("新增用户成长值记录" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('user:userGrowthLog:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid UserGrowthLog userGrowthLog) {
        return ResponseEntity.ok(userGrowthLogService.save(userGrowthLog));
    }

    /**
     * 修改用户成长值记录
     * @param userGrowthLog 用户成长值记录
     * @return 是否修改成功
     */
    @SysLog("修改用户成长值记录" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user:userGrowthLog:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid UserGrowthLog userGrowthLog) {
        return ResponseEntity.ok(userGrowthLogService.updateById(userGrowthLog));
    }

    /**
     * 通过id删除用户成长值记录
     * @param logId id
     * @return 是否删除成功
     */
    @SysLog("删除用户成长值记录" )
    @DeleteMapping("/{logId}" )
    @PreAuthorize("@pms.hasPermission('user:userGrowthLog:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long logId) {
        return ResponseEntity.ok(userGrowthLogService.removeById(logId));
    }

}
